package metier.sess;

import java.util.List;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import metier.entities.TransportCat;


@Stateless(name="TransportCat")
public class TransportCatEJBImpl implements ITransportCatLocal,ITransportCatRemote{
	@PersistenceContext(unitName="PU_Cargaison")
	private EntityManager em;

	@Override
	public void addTransportCat(TransportCat t) {
		
		em.persist(t);
		
	}

	@Override
	public List<TransportCat> getAllTransportCat() {
		Query req=em.createQuery("select tc from TransportCat tc");
        return req.getResultList();
	}
	
	
	@Override
	public List<TransportCat> getAllActiveTransportCat(Integer id) {
		Query req=em.createQuery("select tc from TransportCat tc where tc.Statut=true and  tc.transport.IdTransport="+id);
        return req.getResultList();
	}

	@Override
	public TransportCat getTransportCat(Integer Id) {
		return em.find(TransportCat.class,Id);
	}

	@Override
	public void updateTransportCat(TransportCat t) {
		em.merge(t);
		
	}

	@Override
	public void deleteTransportCat(Integer Id) {
		TransportCat tc=getTransportCat(Id);
		em.remove(tc);
		
	}

}
